﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PhotoGallery.Modules.Authority.Model.AccountRoleEditModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    用户角色编辑 - 重庆市公安图片管理系统
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="con-box">
        <div class="head">
            <h2>
                <a href='<%= Url.Action("Index") %>'>用户角色管理 </a>&gt; 用户角色信息修改</h2>
        </div>
        <div class="con">
            <div class="attributes box">
                <div class="attr-title">
                    <span>用户基本信息:</span></div>
                <ul class="detail-info-list clearfix">
                    <li><span>用户名称：<%: Html.Encode(Model.Account.Name) %></span></li>
                    <li><span>性别：<%: Html.Encode(Model.Account.Gender==0? "女":"男")%></span></li>
                    <li><span>电话：<%: Html.Encode(Model.Account.Telephone)%></span></li>
                    <li><span>生日：<%: Html.Encode(Model.Account.Birthday.ToLongDateString())%></span></li>
                    <li><span>地址：<%: Html.Encode(Model.Account.Address)%></span></li>
                    <li><span>登录名：<%: Html.Encode(Model.Account.LoginName)%></span></li>
                </ul>
            </div>
            <div class="attributes box margint5">
                <div class="attr-title">
                    <span>人员角色</span>
                </div>
            </div>
            <div class="clearfix box">
                <div class="floatl" style="width: 450px">
                    <table id="role-list" style="text-align: center" cellspacing="0" cellpadding="0"
                        class="info-table">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="chk-all" />
                                </th>
                                <th>
                                    角色名称
                                </th>
                                <th>
                                    创建日期
                                </th>
                                <th>
                                    状态
                                </th>
                                </th>
                                <th>
                                    功能总数
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                               
                                foreach (var item in Model.Roles)
                                { 
                            %>
                            <tr id="<%: Html.Encode(item.Id) %>">
                                <td>
                                    <input type="checkbox" name="chk" <%: Model.Account.RoleIds.Contains(item.Id)?"checked='checked'":string.Empty %> />
                                </td>
                                <td>
                                    <%--角色名称--%>
                                    <%: Html.Encode(item.Name) %>
                                </td>
                                <td>
                                    <%--创建日期--%>
                                    <%: Html.Encode(item.AddDate.ToLongDateString()) %>
                                </td>
                                <td>
                                    <%--状态--%>
                                    <%: Html.Encode(item.Status==0?"正常":"禁用") %>
                                </td>
                                <td>
                                    <%-- 功能总数--%>
                                    <%: Html.Encode(item.Operations.Count) %>
                                </td>
                            </tr>
                            <%
                                }                            
                            %>
                        </tbody>
                    </table>
                    <div class="box">
                        <span class="sexybutton" id="btn-submit"><span><span>
                            <input type="submit" class="ok" value="修改" /></span></span></span>
                    </div>
                </div>
            </div>
            <div class="clearfix box">
                <table id="selected-panel" style="text-align: center" cellspacing="0" cellpadding="0"
                    class="info-table">
                    <thead>
                        <tr>
                            <%--<th>
                                <input type="checkbox" id="chkall" />
                            </th>--%>
                            <th>
                                功能名称
                            </th>
                            <th>
                                控制器名称
                            </th>
                            <th>
                                操作名称
                            </th>
                            <th>
                                状态
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <%
                            foreach (var item in Model.Operations)
                            {
                        %>
                        <tr key="<%: Html.Encode(item.Id) %>">
                            <%-- <td>
                                <input type="checkbox" />
                            </td>--%>
                            <td>
                                <%--功能名称--%>
                                <%= item.Name %>
                            </td>
                            <td>
                                <%--  Controller--%>
                                <%= item.Controller %>
                            </td>
                            <td>
                                <%--  Action--%>
                                <%= item.Action %>
                            </td>
                            <td>
                                <%-- 状态--%>
                                <%= Html.Encode(item.Status==0?"正常":"禁用") %>
                            </td>
                        </tr>
                        <%
                                
                            } %>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript" charset="utf-8">
        $(function () {
            //全选
            (function () {
                var chkall = $("#role-list>thead>tr>th>input:checkbox");

                chkall.live("click", function () {
                    $("#role-list>tbody input:checkbox").attr("checked", $(this).is(":checked"));
                    //if ($("#role-list>tbody input:checkbox:checked").length > 0)
                    //$("#deselect-function").attr("disabled", "");
                    //else
                    //$("#deselect-function").attr("disabled", "disabled");

                });

                $("#role-list>tbody input:checkbox").live("click", function () {
                    var total = $("#role-list>tbody input:checkbox"), checked = $("#role-list>tbody input:checkbox:checked");
                    if (checked.length === total.length && !chkall.is(":checked"))
                        chkall.attr("checked", true);
                    if (checked.length === 0 && chkall.is(":checked"))
                        chkall.attr("checked", false);

                    //if (checked.length > 0)
                    //$("deselect-f#unction").attr("disabled", "");
                    //else
                    //$("#deselect-function").attr("disabled", "disabled");
                });
            })();




            $("#btn-submit").live("click", function () {
                var roles = [];
                $("#role-list>tbody>tr").each(function () {
                    if ($(this).find("td>input:checkbox").is(":checked"))
                        roles.push($(this).attr("id"))
                });
                window.console && console.log(roles);
                UpdateRoles(roles);
            });

            function UpdateRoles(roles) {
                if (!roles)
                    return;

                $.ajax({
                    url: '<%: Url.Action("UpdateAccountRoles","AccountRole",new {id=Model.Account.Id}) %>',
                    type: 'POST',
                    data: { strRoleids: JSON.stringify(roles) },
                    dataType: 'json',
                    success: function (data, textStatus) {
                        if (!data)
                            return;
                        if (data.success) {
                            cy.ui.showResult({ content: data.message, disappear: 5000 });
                            window.location.reload();
                        } else {
                            cy.ui.showResult({ content: data.message, disappear: 5000, className: 'cy-ui-results error' });
                        }
                        // updata right;
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {

                    }
                });
            }

        });

        Array.prototype.remove = function (dx) {
            if (isNaN(dx) || dx > this.length) { return false; }
            for (var i = 0, n = 0; i < this.length; i++) {
                if (this[i] != this[dx]) {
                    this[n++] = this[i]
                }
            }
            this.length -= 1
        }

    </script>
</asp:Content>
